package com.wang.result;

import com.wang.constant.CommonConstant;
import com.wang.constant.ErrorCode;

/**
 * 返回工具类
 */
public class ResultUtils {

    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<>(0, data, CommonConstant.SUCCESS);
    }

    public static <T> BaseResponse<T> success() {
        return new BaseResponse<>(0, null, CommonConstant.SUCCESS);
    }

    public static <T> BaseResponsePage<T> pageSuccess(T data) {
        return new BaseResponsePage<>(0, data, CommonConstant.SUCCESS);
    }

    public static <T> BaseResponse<T> error(ErrorCode errorCode) {
        return new BaseResponse<>(errorCode);
    }

    public static <T> BaseResponse<T> error(String  errorStr) {
        return new BaseResponse<>(ErrorCode.SYSTEM_ERROR.getCode(), null, errorStr);
    }

    public static <T> BaseResponsePage<T> pageError(ErrorCode errorCode) {
        return new BaseResponsePage<>(errorCode);
    }

    public static <T> BaseResponse<T> error(int code, String message) {
        return new BaseResponse<T>(code, null, message);
    }

    public static <T> BaseResponse<T> error(ErrorCode errorCode, String message) {
        return new BaseResponse<T>(errorCode.getCode(), null, message);
    }
}
